window.onload = function() {
    file.onchange = function() {
        document.querySelector('form').submit()
    }
    document.querySelector('iframe').onload = function() {
        let selfWindow = this.contentWindow;
        let resultObj = JSON.parse(selfWindow.document.body.innerHTML);
        if (resultObj.code != 0) {
            console.log('请求失败');
            return
        }
        showImg.src = resultObj.uploadUrl;
        selfWindow.document.body.innerHTML = '';
    }
    document.querySelector('button').onclick = async function() {
        let res = await ajax({
            url: '/register',
            type: 'POST',
            params: {
                name: userName.value,
                password: userPassword.value,
                imgsrc: showImg.src
            }
        })
        if (res.code == 0) {
            location.href = '/login';
        }
    }
}